package jp.sourceforge.akjrcp.ffmpeg;

import org.eclipse.ui.PlatformUI;

import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.ui.DirectryBasedExecuterListener;
import jp.sourceforge.akjrcp.util.StatusBarUtils;

public class FFMpegErrorGuide {

	public static String toGuideText(String string){
		StringBuffer log=new StringBuffer();
		log.append(string);
		//append infomation
		//log.info("**"+string);
		if(string.indexOf("unrecognized option '-me_method'")!=-1){
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
			log.append(Messages.getString("ffmpeg_error.unrecognized_me_method")+"\n");
			log.append(Messages.getString("ffmpeg_hint.tooold_ffmpeg")+"\n");
			log.append("\n");
			
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
		}else if(string.indexOf("ffmpeg: unrecognized option")!=-1){
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
			log.append(Messages.getString("ffmpeg_error.unrecognized_option")+"\n");
			log.append(Messages.getString("ffmpeg_hint.update_ffmpeg")+"\n");
			log.append("\n");
			
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
		}else if(string.indexOf(DirectryBasedExecuterListener.ERROR_NOTSUPPORTED_VIDEO)!=-1){
			log.append(Messages.getString("ffmpeg_error.unsupported")+"\n");
			log.append(Messages.getString("ffmpeg_hint.update_ffmpeg")+"\n");
			log.append(Messages.getString("ffmpeg_hint.install_avisynth")+"\n");
			log.append("\n");
			//show error
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
		}else if(string.indexOf(DirectryBasedExecuterListener.ERROR_NOTSUPPORTED_SOMETHING)!=-1){
			log.append(Messages.getString("ffmpeg_error.unsupported_something")+"\n");
			log.append(Messages.getString("ffmpeg_hint.update_ffmpeg")+"\n");
			
			log.append("\n");
			//show error
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
		}else if(string.indexOf(DirectryBasedExecuterListener.ERROR_COULD_NOT_OPEN)!=-1){
			log.append(Messages.getString("ffmpeg_error.could_not_open")+"\n");
			log.append(Messages.getString("ffmpeg_hint.could_not_open")+"\n");
			
			log.append("\n");
			//show error
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
		}else if(string.indexOf("av_interleaved_write_frame():")!=-1){
			log.append(Messages.getString("ffmpeg_error.unsupported_copy_audio")+"\n");
			log.append(Messages.getString("ffmpeg_hint.unsupported_copy_audio")+"\n");
			
			log.append("\n");
			//show error
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
		}else if(string.indexOf("no such file or directory")!=-1 && string.indexOf("?")!=-1){
			log.append(Messages.getString("ffmpeg_error.not_supported_file_name")+"\n");
			log.append(Messages.getString("ffmpeg_hint.not_supported_file_name")+"\n");
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
			
			log.append("\n");
		}else if(string.indexOf("Cannot allocate temp picture, check pix fmt")!=-1 && string.indexOf("?")!=-1){
			log.append(Messages.getString("ffmpeg_error.maybe_lack_of_memory")+"\n");
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
			
			log.append("\n");
		}else if(string.indexOf("PSP mode need one video and one audio stream")!=-1){
			log.append(Messages.getString("ffmpeg_error.psp_neeed_audio_track")+"\n");
			PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("ffmpeg_info.faild")));
			
			log.append("\n");
		}else if(string.indexOf("faac: frame decoding failed: Invalid number of channels")!=-1){
			log.append(Messages.getString("ffmpeg_error.faac_frame_faild")+"\n");
			
			log.append("\n");
		}else if(string.indexOf("unrecognized option '-brdo'")!=-1){
			log.append(Messages.getString("ffmpeg_error.no_brdo")+"\n");
			
			log.append("\n");
		}else if(string.indexOf("unrecognized option")!=-1){
			log.append(Messages.getString("ffmpeg_error.unrecognized_option")+"\n");
			
			log.append("\n");
		}else if(string.indexOf("Invalid value")!=-1){
			log.append(Messages.getString("ffmpeg_error.invalid_value")+"\n");
			
			log.append("\n");
		}
		else if(string.indexOf("Incorrect frame size")!=-1){
			log.append(Messages.getString("ffmpeg_error.Incorrect_frame_size")+"\n");
			
			log.append("\n");
		}
		return log.toString();
	}
}
